package com.yznu.dlm.mvp;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;

import com.yznu.dlm.mvp.Model.Tngou;
import com.yznu.dlm.mvp.Presenter.MainPresenter;
import com.yznu.dlm.mvp.adapter.NewsAdapter;
import com.yznu.dlm.mvp.view.MainView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TngouActivity extends AppCompatActivity implements MainView {


    @BindView(R.id.news_listView)
    ListView newsListView;
    private ProgressBar mProgressBar;
    private MainPresenter mMainPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mProgressBar = (ProgressBar) findViewById(R.id.mProgressBar);
        mMainPresenter = new MainPresenter(this);
        //制造延迟效果
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mMainPresenter.loadData();
            }
        }, 2000);
    }

    @Override
    protected void onDestroy() {
        mMainPresenter.detachView();
        super.onDestroy();
    }

    @Override
    public void showData(Tngou tngou) {
        NewsAdapter adapter = new NewsAdapter(this, tngou.getNewsList());
        Log.i("single", "list" + tngou.getNewsList().get(1).getName());
        newsListView.setAdapter(adapter);
    }

    @Override
    public void showProgress() {
        mProgressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        mProgressBar.setVisibility(View.GONE);
    }
}
